package com.blb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blb.entity.Driver;
import com.blb.entity.Settlement;
import com.blb.mapper.SettlementMapper;
import com.blb.service.ISettlementService;
import com.blb.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaoxiong
 * @since 2020-06-11
 */
@Controller
@RequestMapping("/settlement")
public class SettlementController {

    @Resource
    ISettlementService settlementService;

    @Resource
    SettlementMapper settlementMapper;

    @RequiresPermissions("logisticspay")
    @ResponseBody
    @GetMapping("/list")
    public List<Settlement> list(int page, int limit, String goodId){
        String companyId = ShiroUtils.getCompany();
        Map<String,Object> map = new HashMap<>();
        map.put("companyId", companyId);
        map.put("page",String.valueOf(page));
        map.put("limit",String.valueOf(limit));
        map.put("goodId",goodId);
        List<Settlement> list = settlementMapper.getPageList(map);
        return list;
    }

    @RequiresPermissions("logisticspay")
    @ResponseBody
    @GetMapping("/list2")
    public Page<Settlement> list2(int page, int limit, String goodId){
        return settlementMapper.selectPage(new Page<Settlement>(page,limit),new QueryWrapper<Settlement>().like("id",goodId));
    }

    @RequiresPermissions("logisticspay")
    @ResponseBody
    @RequestMapping("/update")
    public boolean update(Settlement settlement){
        settlement.setSettlement("已结算");
        return settlementService.update(settlement,new UpdateWrapper<Settlement>().eq("id",settlement.getId()));
    }

}

